package com.example.administrator.ygddriver.base;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.example.administrator.ygddriver.R;

public class BaseHint {
    private Context context;
    private String title, content;
    private AlertDialog dialog;
    private boolean tag = true;

    private void initHint() {
        View view = null;
        if (tag) {
            view = LayoutInflater.from(context).inflate(R.layout.item_base_hint, null);
            handleLogic(view, title, content);
        } else {
            view = LayoutInflater.from(context).inflate(R.layout.item_base_hint_loding, null);
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCancelable(false);
        dialog = builder.create();
        dialog.setView(view);
        dialog.show();
    }

    private void handleLogic(View contentView, String title, String content) {
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.item_base_hint_get_tv:

                        dialog.dismiss();
                        break;
                }
            }
        };
        TextView affirmTv = contentView.findViewById(R.id.item_base_hint_get_tv);
        TextView titleTv = contentView.findViewById(R.id.item_base_hint_title_tv);
        TextView contentTv = contentView.findViewById(R.id.item_base_hint_content_tv);
        titleTv.setText(title);
        contentTv.setText(content);
        affirmTv.setOnClickListener(listener);

    }


    public static class addHint {
        private BaseHint baseHint;

        public BaseHint setParameter(Context context, String title, String content) {
            baseHint = new BaseHint();
            baseHint.context = context;
            baseHint.content = content;
            baseHint.title = title;
            return baseHint;

        }

        public BaseHint setParameter(Context context, boolean tag) {
            baseHint = new BaseHint();
            baseHint.context = context;
            baseHint.tag = tag;
            return baseHint;

        }


    }

    public void show() {
        initHint();
    }

    public void dismiss() {
        dialog.dismiss();
    }



}

